package com.web.dao;

import com.web.entity.RolePermissionExample;
import com.web.entity.RolePermissionKey;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface RolePermissionMapper {
    @SelectProvider(type=RolePermissionSqlProvider.class, method="countByExample")
    int countByExample(RolePermissionExample example);

    @DeleteProvider(type=RolePermissionSqlProvider.class, method="deleteByExample")
    int deleteByExample(RolePermissionExample example);

    @Delete({
        "delete from t_role_permission",
        " where role_id = #{roleId,jdbcType=BIGINT}",
          " and permission_id = #{permissionId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(RolePermissionKey key);

    @Insert({
        "insert into t_role_permission (role_id, permission_id)",
        " values (#{roleId,jdbcType=BIGINT}, #{permissionId,jdbcType=BIGINT})"
    })
    int insert(RolePermissionKey record);

    @InsertProvider(type=RolePermissionSqlProvider.class, method="insertSelective")
    int insertSelective(RolePermissionKey record);

    @SelectProvider(type=RolePermissionSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="role_id", property="roleId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="permission_id", property="permissionId", jdbcType=JdbcType.BIGINT, id=true)
    })
    List<RolePermissionKey> selectByExample(RolePermissionExample example);

    @UpdateProvider(type=RolePermissionSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") RolePermissionKey record, @Param("example") RolePermissionExample example);

    @UpdateProvider(type=RolePermissionSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") RolePermissionKey record, @Param("example") RolePermissionExample example);
    @Insert({"<script>",
            "insert into t_role_permission (role_id, permission_id) values ",
            " <foreach  collection='list' item='item' index='index' separator=','>(#{item.roleId,jdbcType=BIGINT}, #{item.permissionId,jdbcType=BIGINT})</foreach>",
            "</script>"
    })
    int batchInsert(List<RolePermissionKey> list);
}